package com.sdehua.wear.controller;

import com.sdehua.wear.entity.Ticket;
import com.sdehua.wear.service.TicketService;
import com.sdehua.wear.utils.ResultEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Ticket)表控制层
 * @author makejava
 * @since 2022-01-03 21:11:04
 */
@RestController
@RequestMapping("ticket")
@CrossOrigin
public class TicketController {
    /**
     * 服务对象
     */
    @Resource
    private TicketService ticketService;

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Ticket selectOne(Integer id) {
        return this.ticketService.queryById(id);
    }

    @RequestMapping("activeCode")
    public ResultEntity activeCode(String code,String userId){
        boolean flag = ticketService.activeCode(code,userId);
        if (flag){
            return ResultEntity.success("激活成功");
        }else {
            return ResultEntity.fail("激活失败");
        }
    }

    @RequestMapping("queryByUserId")
    public ResultEntity queryByUserId(String userId){
        List<Ticket> list = ticketService.queryByUserId(userId);
        if (list == null || list.size() < 1){
            return ResultEntity.fail("查询失败");
        }else {
            return ResultEntity.success(list);
        }
    }

}